package ciyuan.Player;

import ciyuan.Constants.PlayerDataType;
import ciyuan.DataManager.PlayerDataManager;
import net.minecraft.entity.player.ServerPlayerEntity;

import java.util.Arrays;

import static ciyuan.Constants.PlayerDataType.*;

public class AttrbuteService {

    public static void tryAddAttribute(ServerPlayerEntity serverPlayerEntity, String attributeName) {
        int attributePoints = PlayerDataManager.getInt(serverPlayerEntity, PlayerDataType.ATTRBUTE_POINTS);

        if (attributePoints <= 0) {
            return;
        }
        Arrays.stream(PlayerDataType.values())
                .filter(playerData -> playerData.getName().equals(attributeName))
                .filter(playerData -> STRENGTH.equals(playerData) || STRONG.equals(playerData) || AGILE.equals(playerData) || WISDOM.equals(playerData))
                .findAny()
                .ifPresent(playerData -> {
                    int value = PlayerDataManager.getInt(serverPlayerEntity, playerData);
                    PlayerDataManager.setServerPlayerData(serverPlayerEntity, playerData, value + 1);
                    PlayerDataManager.setServerPlayerData(serverPlayerEntity, ATTRBUTE_POINTS, attributePoints - 1);
                });
    }

}
